package com.htt.app.bienbaogiaothong.task;

import java.util.Random;

import android.content.res.AssetManager;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.widget.ImageView;

import com.htt.app.bienbaogiaothong.utils.Utils;

public class LoadImageAssets extends AsyncTask<Void, Void, Drawable>{
	private ImageView imageView;
	private String name;
	private AssetManager assets;
	
	public LoadImageAssets(AssetManager assets,ImageView imageView, String name) {
		// TODO Auto-generated constructor stub
		this.imageView = imageView;
		this.assets = assets;
		if(name == null || name.equals("")) {
			Random r = new Random();
			int index = r.nextInt(12) + 1;
			this.name = String.valueOf(index) + ".jpg";
		} else
			this.name = name;
	}
	
	@Override
	protected Drawable doInBackground(Void... params) {
		// TODO Auto-generated method stub
		return Utils.getImageAssets(assets, name);
	}
	
	@Override
	protected void onPostExecute(Drawable result) {
		// TODO Auto-generated method stub
		try {
			if(result != null)
				imageView.setImageDrawable(result);
		} catch(Exception e) {}
		super.onPostExecute(result);
	}
}
